package de.hb.bv1.example;

import ij.process.ImageProcessor;

/**
 * 2 simple examples how to process an image
 * 
 * @author jworch
 * @version 2011-11-09
 *
 */
public final class Logic {

  /**
   * Invert the whole image
   * 
   * @param ip image to modify
   */
  public static void invert(final ImageProcessor ip) {
    final int h = ip.getHeight();
    final int w = ip.getWidth();
    for (int y = 0; y < h; ++y) {
      for (int x = 0; x < w; ++x) {
        final int p = ip.getPixel(x, y);
        ip.putPixel(x, y, 255 - p);
      }
    }
  }

  
  /**
   * Invert every 4th diagonal
   * 
   * @param ip
   */
  public static void invertDiagonal(final ImageProcessor ip) {
    final int h = ip.getHeight();
    final int w = ip.getWidth();
    for (int y = 0; y < h; ++y) {
      for (int x = 0; x < w; ++x) {
        final int p = ip.getPixel(x, y);
        if ((x + y) % 4 == 0) {
          ip.putPixel(x, y, 255 - p);
        }
      }
    }
  }

}
